home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2337 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.3 KB

  1. Path: mail2news.demon.co.uk!hpl3sn03.cern.ch
  2. From: Dan Pop <danpop@mail.cern.ch>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Segmentation fault at return statement. Can't figure out ....
  5. Date: Sat, 20 Jan 1996 19:45:18 +0100
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <9601201845.AA02887@dxmint.cern.ch>
  8. References: <4dm2n1$egk@murphy.servtech.com> <4dqgr3$626@clare.res.com>
  9. X-NNTP-Posting-Host: hpl3sn03.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11. X-Mail2News-Path: frigate.doc.ic.ac.uk!dxmint.cern.ch!hpl3sn03.cern.ch
  12.  
  13. danlynes@res.com writes:
  14.  
  15. >In <4dm2n1$egk@murphy.servtech.com>, Avijit Dasgupta <avi@servtech.com> writes:
  16. >
  17. >>83: return(999); <----- Segmentation fault at this stmt.
  18. >>}
  19. >>
  20. >>Running dbx I get these error messages:
  21. >>
  22. >>(dbx) where
  23. >>=> [1] test( ) at line 83
  24. >>dbx: bad data address
  25. >>dbx fetch at 0x697075a4 failed - I/O error
  26. >>dbx : attempt to read stack failed - bad frame pointer
  27. >>(dbx)
  28. >>
  29. >>I can't figure out, bcoz this function gets called multiple times and
  30. >>fails only after a fixed X times ... Any Help ? 
  31. >
  32. >My guess would be that you're allocating some memory that you're 
  33. >not freeing up, when returning from the function.  So, after so 
  34. >many calls to it, your stack gets filled up, and refuses to 
  35. >continue running.
  36.  
  37. Huh???  There is no malloc implementation that I know of which allocates
  38. memory on the stack.
  39.  
  40. > i.e.  You have a stack overflow error. 
  41.  
  42. If this is the case (not very likely) it is (probably) because he has
  43. too much automatic data or because of recursing too deeply.
  44.  
  45. >Try 
  46. >proofing your code, to see if there's any memory you're 
  47. >forgetting to deallocate, either by by explicitly allocated 
  48. >memory, or implicitly allocated memory.  
  49.  
  50. Memory leaks don't usually cause stack corruption.
  51.  
  52. My guess (in the absence of enough information) is that the original poster
  53. was doing bad things with pointers and he managed to corrupt the
  54. information stored on the stack.  When the cpu tried to fetch the
  55. return address from the stack, it got some garbage instead and the attempt
  56. to jump to that address caused the segmentation fault.
  57.  
  58. >+------------------------------------------------------+
  59. >!  OS/2         - The Champion of Operating Systems    !
  60.  
  61. It depends on who are the other competitors :-)
  62.  
  63. Dan
  64. -- 
  65. Dan Pop
  66. CERN, CN Division
  67. Email: danpop@mail.cern.ch 
  68. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  69.